package com.example.rabbitmqdemo.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-04-06
 * Time: 14:49
 */
@RequestMapping("/consumer")
@RestController
public class ConsumerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    //拉取消息(只能一个一个拉取)
    @RequestMapping("/get")
    public String get() {
        Message message = rabbitTemplate.receive("cluster.queue");
        System.out.println("获取消息: " + message);
        return "拉取消息";
    }
}
